package gui;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import java.awt.Font;

/**
 * @author Kevin Wagner
 * 
 */
public class LoadWindow extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 768483933097237264L;
	private JPanel contentPane;
	private JPanel wuselPaint = new WuselPanel(60);
	private JLabel stateL = new JLabel("State");
	private JProgressBar progressBar = new JProgressBar();

	/**
	 * Create the frame.
	 */
	public LoadWindow() {
		setUndecorated(true);
		setResizable(false);
		setSize(new Dimension(400, 400));
		setPreferredSize(new Dimension(400, 400));
		setMaximumSize(new Dimension(400, 400));
		setMinimumSize(new Dimension(400, 400));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		int x = (dim.width - 400) / 2;
		int y = (dim.height - 400) / 2;
		setLocation(x, y);

		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		progressBar.setDoubleBuffered(true);
		progressBar.setString("");

		stateL.setFont(new Font("Arial Black", Font.PLAIN, 20));
		stateL.setHorizontalAlignment(SwingConstants.CENTER);
		stateL.setHorizontalTextPosition(SwingConstants.CENTER);

		JLabel lblNewLabel = new JLabel("Starting WUSEL");
		lblNewLabel.setFont(new Font("Westwood LET", Font.PLAIN, 28));
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setHorizontalTextPosition(SwingConstants.CENTER);

		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane
				.setHorizontalGroup(gl_contentPane
						.createParallelGroup(Alignment.TRAILING)
						.addComponent(progressBar, Alignment.LEADING,
								GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
						.addComponent(stateL, Alignment.LEADING,
								GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
						.addGroup(
								Alignment.LEADING,
								gl_contentPane
										.createSequentialGroup()
										.addGap(1)
										.addGroup(
												gl_contentPane
														.createParallelGroup(
																Alignment.LEADING)
														.addComponent(
																lblNewLabel,
																GroupLayout.DEFAULT_SIZE,
																439,
																Short.MAX_VALUE)
														.addComponent(
																wuselPaint,
																GroupLayout.DEFAULT_SIZE,
																439,
																Short.MAX_VALUE))));
		gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(
				Alignment.TRAILING).addGroup(
				gl_contentPane
						.createSequentialGroup()
						.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE,
								34, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(wuselPaint, GroupLayout.DEFAULT_SIZE,
								264, Short.MAX_VALUE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(stateL, GroupLayout.PREFERRED_SIZE, 35,
								GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(progressBar, GroupLayout.PREFERRED_SIZE,
								39, GroupLayout.PREFERRED_SIZE)));
		contentPane.setLayout(gl_contentPane);

		this.setVisible(true);
	}

	/**
	 * Sets the status
	 * 
	 * @param status
	 *            current Status
	 */
	public void setStatus(String status) {
		stateL.setText("State: " + status);
	}

	/**
	 * @param progress
	 *            new progress information
	 */
	public void setProgress(int progress) {
		progressBar.setValue(progress);
	}
}
